<?php
namespace classes\bank;

abstract class BankProduct
{
	
	private $accountNumber;
	private $yearlyInterestRate;
	private $periodInMonts;
	private $nalichnost;
	
	public function __construct($accountNumber, $yearlyInterestRate, $periodInMonts, $nalichnost){
		
		$this->setAccountNumber($accountNumber);
		$this->setYearlyInterestRate($yearlyInterestRate);
		$this->setPeriodInMonts($periodInMonts);
		$this->setNalichnost($nalichnost);
		
	}
								
	public function getAccountNumber()
	{
		return $this->accountNumber;
	}
	
	public function setAccountNumber($accountNumber)
	{
		if(!is_numeric($accountNumber)){
			throw new \Exception("Incorrect variable type");
		}
		if($accountNumber < 0){
			throw new \Exception("Wrong value for account number");		
		}
		$this->accountNumber = $accountNumber;
	}
	
	public function getYearlyInterestRate(){
		return $this->yearlyInterestRate;
	}
	
	private function setYearlyInterestRate($yearlyInterestRate){

		if(!is_numeric($yearlyInterestRate)){
			throw new \Exception("Incorrect variable type");
		}
		if($yearlyInterestRate < 0 || $yearlyInterestRate > 20){
			throw new \Exception("Wrong value for yearly interest rate");		
		}
		$this->yearlyInterestRate = $yearlyInterestRate;
		return true;
	}
	
	public function getPeriodInMonts(){
		return $this->periodInMonts;
	}
	
	public function setPeriodInMonts($periodInMonts){

		if(!is_numeric($periodInMonts)){
			throw new \Exception("Incorrect variable type");
		}
		if($periodInMonts < 1 || $periodInMonts > 60){
			throw new \Exception("Wrong value for period");		
		}
		$this->periodInMonts = $periodInMonts;
		return true;
	}
	
	public function getNalichnost(){
		return $this->nalichnost;
	}
	
	public function setNalichnost($nalichnost)
	{
		if(!is_numeric($nalichnost)){
			throw new \Exception("Incorrect variable type");
		}
		if($nalichnost < 0){
			throw new \Exception("Wrong value for nalichnost");		
		}
		$this->nalichnost = $nalichnost;
		
	}
	
	public function showInfo(){
			 
		echo "Account number: " . $this->accountNumber . "<br>" .
			 "Amount: " . $this->nalichnost . "lv<br>" .
		     "Yearly interest rate: " . $this->yearlyInterestRate . "%<br>" .
			 "Period in monts: "	. $this->periodInMonts . "<br>";
	}
}

?>